<?php

class Application_Model_Dao_DegreeStudy extends Zend_Db_Table_Abstract
{

	protected $_name = 'degree_studies';
    protected $_primary = 'id';
    
	public function init(){
    	
    }
    public function getAll(){
		$result = $this->fetchAll();
		if( !$result )
			throw new Exception("Wystąpił błąd przy pobieraniu danych z bazy. Proszę spróbować jeszcze raz. Jeśli problem będzie się powtarzać, prosimy skontaktować się z administratorem.");	
		return $result;
    }   
public function getAllDegreeStudy(){
		$dbAdapter = Zend_Db_Table::getDefaultAdapter();
		$select = $dbAdapter->select()->from('degree_studies');
		$result = $dbAdapter->fetchAll($select);
		return $result;
	}
public function getRowDegreeStudy($id){
		$dbAdapter = Zend_Db_Table::getDefaultAdapter();
		$select = $dbAdapter->select()->from('degree_studies')->where('degree_studies.id = \''.$id.'\'');
		$result = $dbAdapter->fetchAll($select);
		return $result;
	}
	public function getDegreeStudyByID($id){
		$id = (int)$id;
		$row = $this->fetchRow('id = '.$id);
		if (!$row)
			throw new Exception("Stopień studiów o ID $id nie istnieje.");
		return $row->toArray();
	}
	public function getADegreeStudyByDesignation($designation){
		$row = $this->fetchRow('designation = '.$designation);
		if (!$row)
			throw new Exception("Stopień studiów o nazwie $designation nie istnieje.");
		return $row->toArray();
	}
  	public function saveDegreeStudy($degreeStudy) {
    	$data = array(
			'designation' => $degreeStudy->getDesignation()
		);
		$this->insert($data);
     return ;
    }
	public function updateDegreeStudy($degreeStudy) {
		$data = array(
			'designation' => $degreeStudy->getDesignation(),
		);
		$this->update($data, 'id = '. (int)$degreeStudy->getId());
		return ;
	}
public function deleteDegreeStudy($degreeStudy){
		$this->delete('id =' . (int)$degreeStudy->getId());
		return;
	}
  	public function getToSelect(){
    	$array = $this->getAll()->toArray();
    	$degreeStudies[''] = "wybierz";
    	foreach ($array as $option) {
     	$degreeStudies[ $option['id'] ] = $option['designation' ] ;
     }
     return $degreeStudies;
    }
        
}
   